package cn.elricyu.tt.action.army;

import net.sf.json.JSON;
import cn.elricyu.tt.action.base.AbstractAction;
import cn.elricyu.tt.bean.User;
import cn.elricyu.tt.bean.army.Draught;
import cn.elricyu.tt.bean.city.MyBuilding;
import cn.elricyu.tt.exception.ActionException;
import cn.elricyu.tt.util.JsonUtil;

public class PreDraughtAction extends AbstractAction<MyBuilding> {
	private User self;

	public PreDraughtAction(User self) {
		this.self = self;
		this.url = "root/mainCity!preDraught.action";
	}

	@Override
	public void process(JSON json) throws ActionException {
		int state = JsonUtil.getIntValue(json, "state", 0);
		Draught draught = self.getMyArmy().getDraught();
		if (state == 1) {
			int forcemax = JsonUtil.getIntValue(json, "forcemax", 0);
			double recruits = JsonUtil.getDoubleValue(json, "recruits", 0d);
			int rightcd = JsonUtil.getIntValue(json, "rightcd", 0);
			if (draught == null) {
				draught = new Draught();
				self.getMyArmy().setDraught(draught);
			}
			draught.setForcemax(forcemax);
			draught.setRecruits(recruits);
			draught.setRightcd(rightcd);
		}
	}
}
